package cn.mill.core.utils;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class PropertiesUtil {
	private static Logger logger = LoggerFactory.getLogger(PropertiesUtil.class);
	
	private Properties properties;
	
	public PropertiesUtil() {
		this.load();
	}
	
	public void load() {
		this.properties = new Properties();
		// 使用ClassLoader加载properties配置文件生成对应的输入流
		InputStream in = ConfigBuilder.class.getClassLoader().getResourceAsStream("mill.properties");
		// 使用properties对象加载输入流
		try {
			properties.load(in);
		} catch (IOException e) {
			logger.error("PropertiesUtil", e);
		}
	}
	
	public String getProperty(String key) {
		if (NormUtil.isNotEmpty(key)) {
			return properties.getProperty(key);
		}
		return null;
	}
	
	public Properties getProperties() {
		return properties;
	}
	
	public void setProperties(Properties properties) {
		this.properties = properties;
	}
}
